package com.xiaozhen.driver.controller;

import com.xiaozhen.security.controller.BaseController;
import com.xiaozhen.common.core.domain.AjaxResult;
import com.xiaozhen.common.core.domain.driver.ParseTcpAttribute;
import com.xiaozhen.driver.service.ParseTcpAttributeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;


/**
 * HISTORY
 *
 * @author zhenweisheng
 * @date 2021/9/29 9:24
 * @description:
 */
@RestController
@Api(tags = "驱动属性管理接口")
@RequestMapping("/parseAttribute")
public class ParseTcpAttributeController extends BaseController {

    @Autowired
    private ParseTcpAttributeService parseAttributeService;

    @ApiOperation("获取属性列表")
    @GetMapping("/list")
    public AjaxResult list(@RequestParam("driverId") Long driverId) {
        List<ParseTcpAttribute> attributes = parseAttributeService.selectAttributeList(driverId);
        return AjaxResult.success(attributes);
    }

    @ApiOperation("添加属性信息")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody ParseTcpAttribute parseAttribute) {
        parseAttribute.setCreateBy(getCurrentUserId());
        parseAttribute.setCreateTime(LocalDateTime.now());
        return toAjax(parseAttributeService.insertAttribute(parseAttribute));
    }

    @ApiOperation("修改属性信息")
    @PutMapping("/update")
    public AjaxResult edit(@Validated @RequestBody ParseTcpAttribute parseAttribute) {
        parseAttribute.setUpdateBy(getCurrentUserId());
        parseAttribute.setUpdateTime(LocalDateTime.now());
        return toAjax(parseAttributeService.updateAttribute(parseAttribute));
    }

    @ApiOperation("删除属性信息")
    @DeleteMapping("/{attributeId}")
    public AjaxResult remove(@PathVariable("attributeId") Long attributeId) {
        return toAjax(parseAttributeService.deleteAttributeById(attributeId));
    }
}
